package patrol.mobile.com.mobilepatrol.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.MessageDetailBean;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;
import patrol.mobile.com.mobilepatrol.utils.GsonUtil;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;

public class MessageDetailActivity extends BaseActivity {

    private static final String TAG = "MessageDetailActivity";
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.tv_send_name)
    TextView tvSendName;
    @BindView(R.id.tv_receive_name)
    TextView tvReceiveName;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_title)
    TextView tvTitle;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_message_detail;
    }

    @Override
    public void initTitle() {
        super.initTitle();
        iv_back.setImageResource(R.mipmap.up_white);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CommonUtil.exitActivityAndBackAnim(MessageDetailActivity.this, true);
            }
        });
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText("通知");
    }

    @Override
    public void initData() {
        super.initData();
        Bundle extras = getIntent().getExtras();
        String id = extras.getString("id");
        HttpSender sender = new HttpSender(this, baseUrl, Urls.MESSAGE_DETAILS);
        sender.requestPost("id", id, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response) {
                MessageDetailBean messageDetailBean = GsonUtil.GsonToBean(response, MessageDetailBean.class);
                tvTitle.setText(messageDetailBean.getTitle());
                tvContent.setText("          " + messageDetailBean.getContext());
                tvSendName.setText("发送人：" + messageDetailBean.getSender());
                tvReceiveName.setText("接收人：" + messageDetailBean.getReceiver());
                tvTime.setText(messageDetailBean.getSendDate());
            }
        });
    }

    @Override
    public void setListener() {

    }
}
